﻿using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TXTD.Admin.Data.Entitys.System;
using TXTD.Admin.Interface.System;

namespace TXTD.Admin.Service.System
{
    public class SysUserRefreshTokenService : BaseService<SysUserRefreshToken>, ISysUserRefreshTokenService
    {
        public SysUserRefreshTokenService(DbContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
        {
        }

        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public int Add(SysUserRefreshToken model)
        {
            return InsertModel(model);
        }
        /// <summary>
        /// 根据token获取实体
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public SysUserRefreshToken GetModelByToken(string token)
        {
            return QueryAllData().FirstOrDefault(t => t.Token == token);
        }

        /// <summary>
        /// 修改数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public int Update(SysUserRefreshToken model)
        {
            return UpdateModel(model, model.UserRefreshTokenId);
        }
    }
}
